package com.android.powerbankpad.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import com.android.powerbankpad.LauncherActivity;
import com.android.powerbankpad.config.Constants;
import com.ws.universal.tools.eventbus.BaseBusData;
import com.ws.universal.tools.eventbus.EventBusUtil;
import com.ws.universal.tools.utils.LogcatUtils;

public class StartingUpReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
            //接收开机广播
            String device = Build.DEVICE;
            LogcatUtils.e(" StartingUpReceiver onReceive() 开机了: " + " device " + device);
            startLauncherActivity(context);
            LogcatUtils.e(" StartingUpReceiver 执行拉起广告Apk ");
        } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { //更换语言后重启APP
            BaseBusData beautyDate = new BaseBusData(Constants.reboot_app);
            EventBusUtil.postEvent(beautyDate);
        }


    }

    private void startLauncherActivity(Context context) {
        Intent intent3 = new Intent(context, LauncherActivity.class);
        intent3.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent3);

    }
}
